﻿using System;
using System.Collections.Generic;
using System.Text;
using ArkEC.SEMs.BizObject.UM;
using System.Data.Common;
using System.Data.OleDb;
using ArkEC.CoreCom.Datastruct;

namespace ArkEC.SEMs.DataAccess.UM.Implement.Access
{
    /// <summary>
    /// 用户数据库操作接口的实现类(Access)
    /// </summary>
    public class UserDA_Acs : IUserDA
    {
        /// <summary>
        /// 通过邮箱和密码获取用户数据
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="tran"></param>
        /// <param name="email"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public User QueryUser(DbConnection conn, DbTransaction tran, string email, string pwd)
        {
            string sql = @"select UserId, Name from [User] where Email=@Email and Pwd=@Pwd";
            DbCommand cmd = conn.CreateCommand();
            cmd.CommandText = sql;
            cmd.Transaction = tran;

            OleDbParameter[] arrParams = new OleDbParameter[] { 
				new OleDbParameter("@Email", email),
                new OleDbParameter("@Pwd", pwd)
			};
            cmd.Parameters.AddRange(arrParams);
            User obj = null;
            using (OleDbDataReader reader = cmd.ExecuteReader() as OleDbDataReader)
            {
                if (reader.HasRows)
                {
                    obj = new User();
                    while (reader.Read())
                    {
                        obj.UserId = ObjectConvertion.DbToInt(reader["UserId"]);
                        obj.Name = ObjectConvertion.DbToString(reader["Name"]);
                    }
                }
            }
            return obj;
        }
    }
}
